package com.b2s.scrumblr.kb.controller;

import com.b2s.scrumblr.kb.model.User;
import com.b2s.scrumblr.kb.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * Created by Administrator on 2016/8/29.
 */
@Controller
@RequestMapping("/login")
public class LoginController {

    @Resource
    private UserService userService;

    @RequestMapping(method = RequestMethod.GET)
    public String login(){
        return "login";
    }

    @RequestMapping(method = RequestMethod.POST)
    public String login(User user, HttpServletRequest request){
        User result = userService.findUser(user);
        request.getSession().setAttribute("user", result);
        if(result != null){
            return "main";
        }
        return "login";
    }

}
